//
//  SSSexchangeDetailController.m
//  SSSAllRollAgency
//
//  Created by Darker on 2017/3/13.
//  Copyright © 2017年 Darker. All rights reserved.
//

#import "SSSexchangeDetailController.h"
#import "exchangeDetailCell.h"
#import "ExchangeDetailModel.h"
@interface SSSexchangeDetailController ()<UITableViewDelegate,UITableViewDataSource>
{
    
    NSArray *_dataArray;
    UIImageView *_bgImageView;//背景图
    NSArray *_descArray;
    UITableView *_listTableView;
    NSString *timeStr;
    ExchangeDetailModel *_exchangeDetailModel;
    NSString *statusStr;//状态
}
@end

static NSString * const exchangeDetailID = @"exchangeDetailCell";

@implementation SSSexchangeDetailController
- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    self.title = @"兑换详情";
    self.navigationController.navigationBar.hidden = NO;
    [QMUITips showLoading:@"加载中..." detailText:nil inView:self.view];
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self reloadEchangeDetailData];
    //创建界面
    [self setUpUI];
    [self initListTableView];
}
#pragma mark - 创建界面
- (void)setUpUI{
    
    
    _bgImageView = [[UIImageView alloc]initWithFrame:self.view.frame];
    _bgImageView.image = [UIImage imageNamed:@"bg_1"];
    _bgImageView.userInteractionEnabled = YES;
    [self.view addSubview:_bgImageView];
    
    
    
}
- (void)initListTableView{
    
    _listTableView = [[UITableView alloc]initWithFrame:CGRectMake(0,0, FSCREEN_Width, FSCREEN_Height) style:UITableViewStylePlain];
    _listTableView.backgroundColor = [UIColor clearColor];
    _listTableView.delegate = self;
    _listTableView.dataSource = self;
    _listTableView.rowHeight = HeigthIos6CompeteWithCurrent(51);
    _listTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_bgImageView addSubview:_listTableView];
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return _dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    Class currentClass = [exchangeDetailCell class];
    
    exchangeDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(currentClass)];
    //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    if (!cell) {
        cell = [[exchangeDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:exchangeDetailID];
    }
    //cell.nameLabel.text = [NSString stringWithFormat:@"%@",_mDelegateArray[indexPath.row]];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.nameLabel.text = _dataArray[indexPath.row];
    cell.descLabel.text = _descArray[indexPath.row];
    return cell;
}

- (void)reloadEchangeDetailData{
    
    //NSString *UserInfoUrl = [NSString stringWithFormat:@"%@%@",SSSCommomUrl,@"agApi/exchange/queryExcDetail"];
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"id"] = self.idStr;
    
    [[XHRequestManager manager] getRequest:kConfigPath(kExchangeRecrodDetail) params:params success:^(id  _Nonnull responseObj) {
        
        XHLog(@"--userInfo--- %@",responseObj);
        _exchangeDetailModel = [ExchangeDetailModel modelWithJSON:responseObj[@"data"]];
        XHLog (@"---model.bunkNu---%@",_exchangeDetailModel.bunkNu);
        
        [QMUITips showLoading:@"加载中..." inView:_bgImageView hideAfterDelay:1];
        
        if ([responseObj[@"status"] intValue] == 0) {
            
            if (!responseObj[@"data"]) {
                
                [QMUITips showError:@"用户数据为空" inView:self.view hideAfterDelay:2];
                return ;
                
            }else{
                [QMUITips showSucceed:@"加载成功" inView:self.view hideAfterDelay:0.5];
                dispatch_async(dispatch_get_main_queue(), ^{
                    _dataArray = @[@"姓名",@"申请时间",@"开户行",@"银行账号",@"兑换善点",@"手续费",@"实际到账",@"状态"];
                    if ([NSString stringWithFormat:@"%@",_exchangeDetailModel.creatTime].length <= 0) {
                        
                        //_exchangeDetailModel.creatTime = @"";
                        timeStr = @"";
                    }else{
                        
                        //NSString *subStr = [_exchangeDetailModel.creatTime substringWithRange:NSMakeRange(0,_exchangeDetailModel.creatTime.length - 3)];
                        timeStr = [_exchangeDetailModel.creatTime xhstringWithFormat:@"yyyy-MM-dd"];
                    }
                    if (_exchangeDetailModel.status == 0) {
                        
                        statusStr = @"待打款";
                    }else{
                        statusStr = @"打款成功";
                    }
                    _descArray = @[_exchangeDetailModel.name,timeStr,_exchangeDetailModel.bunkName,_exchangeDetailModel.bunkNu,[NSString stringWithFormat:@"%@",_exchangeDetailModel.goodNu],[NSString stringWithFormat:@"%@",_exchangeDetailModel.poundage],[NSString stringWithFormat:@"%@",_exchangeDetailModel.account],statusStr];
                    
                    //刷新表格
                    [_listTableView reloadData];
                });
            }
        }else{
                [QMUITips hideAllToastInView:self.view animated:YES];
                [QMUITips showError:responseObj[@"message"] inView:self.view hideAfterDelay:2];
            }


        
    } failure:^(NSError * _Nonnull error) {
        
        [QMUITips hideAllToastInView:self.view animated:YES];
        XHLog(@"error -- %@",error.localizedDescription);
        [QMUITips showError:error.localizedDescription inView:self.view hideAfterDelay:2];

    }];
    
//    [ZDNetManager zd_requestWithType:ZDHttpRequestTypeGet UrlString:kConfigPath(kExchangeRecrodDetail) Parameters:params SuccessBlock:^(id response) {
//        
//        XHLog(@"--userInfo--- %@",response);
//        _exchangeDetailModel = [ExchangeDetailModel modelWithJSON:response[@"data"]];
//        XHLog (@"---model.bunkNu---%@",_exchangeDetailModel.bunkNu);
//        
//        [QMUITips showLoading:@"加载中..." inView:_bgImageView hideAfterDelay:1];
//        
//        if ([response[@"status"] intValue] == 0) {
//            
//            if (!response[@"data"]) {
//                
//                [QMUITips showError:@"用户数据为空" inView:self.view hideAfterDelay:2];
//                return ;
//                
//            }else{
//                [QMUITips showSucceed:@"加载成功" inView:self.view hideAfterDelay:0.5];
//                dispatch_async(dispatch_get_main_queue(), ^{
//                    _dataArray = @[@"姓名",@"申请时间",@"开户行",@"银行账号",@"兑换善点",@"手续费",@"实际到账",@"状态"];
//                    if (_exchangeDetailModel.creatTime.length<=0) {
//                        
//                        _exchangeDetailModel.creatTime = @"";
//                        
//                    }else{
//                        
//                        NSString *subStr = [_exchangeDetailModel.creatTime substringWithRange:NSMakeRange(0,_exchangeDetailModel.creatTime.length - 3)];
//                        timeStr = [NSString timeDateStrFromTimeStamp:subStr];
//                    }
//                    if (_exchangeDetailModel.status == 0) {
//                        
//                        statusStr = @"待打款";
//                    }else{
//                        statusStr = @"打款成功";
//                    }
//                    _descArray = @[_exchangeDetailModel.name,timeStr,_exchangeDetailModel.bunkName,_exchangeDetailModel.bunkNu,[NSString stringWithFormat:@"%@",_exchangeDetailModel.goodNu],[NSString stringWithFormat:@"%@",_exchangeDetailModel.poundage],[NSString stringWithFormat:@"%@",_exchangeDetailModel.account],statusStr];
//                    
//                    //刷新表格
//                    [_listTableView reloadData];
//                });
//            }
//            
//        }else{
//            [QMUITips hideAllToastInView:self.view animated:YES];
//            [QMUITips showError:response[@"message"] inView:self.view hideAfterDelay:2];
//        }
//        
//    } FailureBlock:^(NSError *error) {
//        [QMUITips hideAllToastInView:self.view animated:YES];
//        XHLog(@"error -- %@",error.localizedDescription);
//        [QMUITips showError:error.localizedDescription inView:self.view hideAfterDelay:2];
//        
//    } progress:^(int64_t bytesProgress, int64_t totalBytesProgress) {
//        
//        
//    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
